#include "slave.h"
#include "master.h"
#include "raytrace.h"

#include <mpi.h>

/**
 * Name: main
 *
 * Description:
 * Run with the '-h' flag for a usage statement.
 *
 * Parameters:
 * @param argc    number of command line arguments
 * @param argv    the actual command line arguments
 *
 * Returns:
 * @return int    0 if all went OK, 1 otherwise
 */
int main( int argc, char **argv )
{
  ConfigData data;

  // Initialize everything. This function will call MPI_Init().
  if (!initialize( &argc, &argv, &data )) {
    // Something went wrong.
    MPI_Abort( MPI_COMM_WORLD, MPI_ERR_UNKNOWN );
  }

  // Proceed to either the slave or master main function.
  if (data.mpi_rank == 0) {
    masterMain( &data );
  }else {
    slaveMain( &data );
  }

  // Clean up. This function will free up memory allocated by the initialize()
  // function, and will call MPI_Finalize().
  shutdown( &data );

  return 0;
}
